import React from 'react';
import { Route } from 'react-router-dom';
import { getToken } from 'utils/storage';

export default function AuthRoute(props) {
  const { path, component: Comp, ...restProps } = props;
  // console.log(restProps);
  return (
    <Route
      // ...restProps 其他配置
      {...restProps}
      path={path}
      render={(props) => {
        // console.log(props);
        if (getToken()) {
          return <Comp {...props}></Comp>;
        } else {
          props.history.push('/login');
        }
      }}
    ></Route>
  );
}
